package com.zretc.controller;

import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 新闻管理的Servlet
 * /news.do web 请求地址
 * 1 .NewsServlet extends HttpServlet 继承关系
 * 2.访问一个servlet的时候，每次访问都会创建Servlet对象吗?
 *    servelt是单例，首次访问才执行构造[tomcat启动，servelt对象就创建？]
 *    
 * 3.servlet的生命周期:
 *   类加载，构造，初始化，服务，销毁。[简单写法]
 *    
 * 
 */
@WebServlet("/news.do")
public class NewsServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public NewsServlet() {
       System.out.println("NewsServlet的构造方法");
    }

	/**
	 * @see Servlet#init(ServletConfig)
	 */
	public void init(ServletConfig config) throws ServletException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see Servlet#destroy()
	 */
	public void destroy() {
		// TODO Auto-generated method stub
	}


	/**
	 * @see 处理get请求；表单method=get; ajax请求; type:get 超链接 a href="news.do?...."
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see 用来处理post请求; 表单method="post"  ajax: type:post 
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
